@extends('admin.layout.layout', ['row' => @$page])

@section('title', @$page['title'])

@section('contain')
    <link rel="stylesheet" href="/dist/admin/stat.css">
    <div class="container" style="background-color: #f7f9fa;padding-bottom: 20px; padding-top: 20px;max-width: 1300px;">
        <div class="widget-container-box" style="width: 100%; padding: 10px;">国代</div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计漆膜/窗膜销售卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/sales?type=1&user_type=1"><span style="font-size: 1.5rem;" id="roll_qm_1"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/sales?type=2&user_type=1"><span style="font-size: 1.5rem;" id="roll_win_1"></span> 卷</a>
                </p>
                <p class="show-percent">
                    漆/窗 同比 <span style="color:#95F204" id="roll_qm_rate_1"></span> / <span style="color:#95F204" id="roll_win_rate_1"></span>
                </p>
                <p class="show-percent">
                    漆/窗 环比 <span style="color:#95F204" id="roll_qm_rate_2"></span> / <span style="color:#95F204" id="roll_win_rate_2"></span>
                </p>
            </div>
        </div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计漆膜/窗膜库存卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/compareRoll?type=1"><span style="font-size: 1.5rem;" id="roll_qm_2"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/compareRoll?type=2"><span style="font-size: 1.5rem;" id="roll_win_2"></span> 卷</a>
                </p>
                <p class="show-percent"></p>
                <p class="show-percent"></p>
            </div>
        </div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计漆膜/窗膜调货卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/transfer?type=1&user_type=1"><span style="font-size: 1.5rem;" id="roll_qm_3"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/transfer?type=2&user_type=1"><span style="font-size: 1.5rem;" id="roll_win_3"></span> 卷</a>
                </p>
                <p class="show-percent">
                    漆/窗 同比 <span style="color:#95F204" id="roll_qm_rate_3"></span> / <span style="color:#95F204" id="roll_win_rate_3"></span>
                </p>
                <p class="show-percent">
                    漆/窗 环比 <span style="color:#95F204" id="roll_qm_rate_4"></span> / <span style="color:#95F204" id="roll_win_rate_4"></span>
                </p>
            </div>
        </div>
        <div class="widget-container" style="min-height: 200px;">
        </div>
        <div class="widget-container-box" style="width: 100%; padding: 10px;">省代</div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计省代漆膜/窗膜销售卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/sales?type=1&user_type=2"><span style="font-size: 1.5rem;" id="roll_qm_4"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/sales?type=2&user_type=2"><span style="font-size: 1.5rem;" id="roll_win_4"></span> 卷</a>
                </p>
                <p class="show-percent">
                    漆/窗 同比 <span style="color:#95F204" id="roll_qm_rate_5"></span> / <span style="color:#95F204" id="roll_win_rate_5"></span>
                </p>
                <p class="show-percent">
                    漆/窗 环比 <span style="color:#95F204" id="roll_qm_rate_6"></span> / <span style="color:#95F204" id="roll_win_rate_6"></span>
                </p>
            </div>
        </div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计省代漆膜/窗膜库存卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/compareAbbrRoll?type=1&user_type=2"><span style="font-size: 1.5rem;" id="roll_qm_5"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/compareAbbrRoll?type=2&user_type=2"><span style="font-size: 1.5rem;" id="roll_win_5"></span> 卷</a>
                </p>
                <p class="show-percent">
                </p>
                <p class="show-percent">
                </p>
            </div>
        </div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计省代漆膜/窗膜调货卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/transfer?type=1&user_type=2"><span style="font-size: 1.5rem;" id="roll_qm_6"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/transfer?type=2&user_type=2"><span style="font-size: 1.5rem;" id="roll_win_6"></span> 卷</a>
                </p>
                <p class="show-percent">
                    漆/窗同比 <span style="color:#95F204" id="roll_qm_rate_7"></span> / <span style="color:#95F204" id="roll_win_rate_7"></span>
                </p>
                <p class="show-percent">
                    漆/窗 环比 <span style="color:#95F204" id="roll_qm_rate_8"></span> / <span style="color:#95F204" id="roll_win_rate_8"></span>
                </p>
            </div>
        </div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计省代漆膜/窗膜退货卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/return?type=1&user_type=2"><span style="font-size: 1.5rem;" id="roll_qm_7"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/return?type=2&user_type=2"><span style="font-size: 1.5rem;" id="roll_win_7"></span> 卷</a>
                </p>
                <p class="show-percent">
                    漆/窗 同比 <span style="color:#95F204" id="roll_qm_rate_9"></span> / <span style="color:#95F204" id="roll_win_rate_9"></span>
                </p>
                <p class="show-percent">
                    漆/窗 环比 <span style="color:#95F204" id="roll_qm_rate_10"></span> / <span style="color:#95F204" id="roll_win_rate_10"></span>
                </p>
            </div>
        </div>
        <div class="widget-container-box" style="width: 100%; padding: 10px;">经销商</div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计经销商漆膜/窗膜销售卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/sales?type=1&user_type=3"><span style="font-size: 1.5rem;" id="roll_qm_8"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/sales?type=2&user_type=3"><span style="font-size: 1.5rem;" id="roll_win_8"></span> 卷</a>
                </p>
                <p class="show-percent">
                    漆/窗 同比 <span style="color:#95F204" id="roll_qm_rate_11"></span> / <span style="color:#95F204" id="roll_win_rate_11"></span>
                </p>
                <p class="show-percent">
                    漆/窗 环比 <span style="color:#95F204" id="roll_qm_rate_12"></span> / <span style="color:#95F204" id="roll_win_rate_12"></span>
                </p>
            </div>
        </div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计经销商漆膜/窗膜库存卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/compareAbbrRoll?type=1&user_type=3"><span style="font-size: 1.5rem;" id="roll_qm_9"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/compareAbbrRoll?type=2&user_type=3"><span style="font-size: 1.5rem;" id="roll_win_9"></span> 卷</a>
                </p>
                <p class="show-percent"></p>
                <p class="show-percent"></p>
            </div>
        </div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计经销商漆膜/窗膜调货卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/transfer?type=1&user_type=3"><span style="font-size: 1.5rem;" id="roll_qm_10"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/transfer?type=2&user_type=3"><span style="font-size: 1.5rem;" id="roll_win_10"></span> 卷</a>
                </p>
                <p class="show-percent">
                    漆/窗 同比 <span style="color:#95F204" id="roll_qm_rate_13"></span> / <span style="color:#95F204" id="roll_win_rate_13"></span>
                </p>
                <p class="show-percent">
                    漆/窗 环比 <span style="color:#95F204" id="roll_qm_rate_14"></span> / <span style="color:#95F204" id="roll_win_rate_14"></span>
                </p>
            </div>
        </div>
        <div class="widget-container">
            <div class="widget-content-container widget-content-container-title" style="">
                <h6 class="card-title">今年|累计经销商漆膜/窗膜退货卷数</h6>
                <h6 class="card-subtitle mb-2 text-muted">{{ date('Y') . '/1/1'  }}~{{ date('Y/m/d') }}</h6>
                <p>
                    <a href="/admin/stat_compare/return?type=1&user_type=3"><span style="font-size: 1.5rem;" id="roll_qm_11"></span>&nbsp;&nbsp;卷</a>
                    /
                    <a href="/admin/stat_compare/return?type=2&user_type=3"><span style="font-size: 1.5rem;" id="roll_win_11"></span> 卷</a>
                </p>
                <p class="show-percent">
                <div style="width: 50%;float: left;">漆膜同比 <span style="color:#95F204" id="roll_qm_rate_15"></span></div>
                <div style="width: 50%;float: left;">窗膜同比 <span style="color:#95F204" id="roll_win_rate_15"></span></div>
                </p>
                <p class="show-percent">
                <div style="width: 50%;float: left;">漆膜环比 <span style="color:#95F204" id="roll_qm_rate_16"></span></div>
                <div style="width: 50%;float: left;">窗膜环比 <span style="color:#95F204" id="roll_win_rate_16"></span></div>
                </p>
            </div>
        </div>
        <br clear="all" />
        <div style="width: 50%;float: left; padding: 5px 10px;">
            <div style="float: left; width: 20%;">
                <button type="button" class="btn btn-secondary" id="all_country">全国</button>
            </div>
            <div style="float: left; width: 40%;">
                <div class="input-group mb-3 custom-control-inline">
                    <div class="input-group-prepend">
                        <span class="input-group-text">省代</span>
                    </div>
                    <select class="form-control" style="width: 60%" id="distributions">
                        <option selected disabled value="">选择省代</option>
                        @if (!empty($distributions))
                            @foreach($distributions as $distribution)
                                <option value="{{ $distribution->id }}">{{ $distribution->abbr }}</option>
                            @endforeach
                        @endif
                    </select>
                </div>
            </div>
            <div style="float: left; width: 40%;">
                <div class="input-group mb-3 custom-control-inline">
                    <div class="input-group-prepend" style="width: 30%;">
                        <span class="input-group-text">经销商</span>
                    </div>
                    <select class="form-control" style="width: 70%" id="dealers">
                        <option selected disabled value="">选择经销商</option>
                    </select>
                </div>
            </div>
        </div>
        <div style="width: 50%;float: left; padding: 5px 10px;">
            <div class="input-group mb-3 custom-control-inline" style="float: left; width: 40%;">
                <div class="input-group-prepend">
                    <span class="input-group-text">年份</span>
                </div>
                <select class="form-control" style="width: 50%;" id="year">
                    @for ($i = date('Y'); $i >= 2016; $i--)
                        <option value="{{ $i }}">{{ $i }}</option>
                    @endfor
                </select>
            </div>
            <div class="input-group mb-3 custom-control-inline" style="float: left; width: 40%;">
                <div class="input-group-prepend">
                    <span class="input-group-text">月份</span>
                </div>
                <select class="form-control" style="width: 50%;" id="month">
                    <option value="">月份总计</option>
                    <option value="01">1</option>
                    <option value="02">2</option>
                    <option value="03">3</option>
                    <option value="04">4</option>
                    <option value="05">5</option>
                    <option value="06">6</option>
                    <option value="07">7</option>
                    <option value="08">8</option>
                    <option value="09">9</option>
                    <option value="10">10</option>
                    <option value="11">11</option>
                    <option value="12">12</option>
                </select>
            </div>
        </div>
        <div class="widget-container widget-container-show">
            <div class="widget-content-container">
                <div class="row show-title" >
                    <div class="col">漆膜销售情况</div>
                    <div class="col" style="text-align: center">
                        <span class="year">{{ $year }}</span>年<span class="month"></span>
                    </div>
                    <div class="col" style="text-align: right;">
                        <a href="/admin/stat_compare/compare_qm_rolls">
                            <span style="cursor: pointer">对比</span>
                        </a>
                    </div>
                </div>
                <div class="show_line_area" id="roll_sale"></div>
            </div>
        </div>
        <div class="widget-container widget-container-show">
            <div class="widget-content-container">
                <div class="row show-title">
                    <div class="col">漆膜单品销量排名</div>
                    <div class="col" style="text-align: center;">
                        <span class="year">{{ $year }}</span>年<span class="month qm_month"></span>
                    </div>
                    <div class="col" style="text-align: right;">
                        <span id="qm_more" style="cursor: pointer;">查看更多</span>
                        <span id="return_qm_show" style="display: none; cursor: pointer;">返回</span>
                    </div>
                </div>
                <div class="show_line_area" id="roll_1"></div>
            </div>
        </div>
        <div class="widget-container widget-container-show">
            <div class="widget-content-container">
                <div class="row show-title">
                    <div class="col">窗膜单品情况</div>
                    <div class="col" style="text-align: center;">
                        <span class="year">{{ $year }}</span>年<span class="month"></span>
                    </div>
                    <div class="col" style="text-align: right;">
                        <a href="/admin/stat_compare/compare_win_rolls">
                            <span style="cursor: pointer">对比</span>
                        </a>
                    </div>
                </div>
                <div class="show_line_area" id="roll_2"></div>
            </div>
        </div>
        <div class="widget-container widget-container-show">
            <div class="widget-content-container">
            <div class="row show-title">
                <div class="col">窗膜单品销量排名</div>
                <div class="col" style="text-align: center">
                    <span class="year">{{ $year }}</span>年<span class="month win_month"></span>
                </div>
                <div class="col" style="text-align: right;">
                    <span id="win_more" style="cursor: pointer;">查看更多</span>
                    <span id="return_win_show" style="display: none; cursor: pointer;">返回</span>
                </div>
            </div>
            <div class="show_line_area" id="single_roll"></div>
            </div>
        </div>
        <br clear="all" />
        <input type="hidden" id="qm_month" value="" />
        <input type="hidden" id="win_month" value="" />
    </div>
    </div>
@endsection
@section('script')
    <script src="https://code.highcharts.com/highcharts.src.js"></script>
    <!--<script src="https://img.hcharts.cn/highmaps/modules/map.js"></script>-->
    <script type="text/javascript">
        let months = {
            '一月' : 1,
            '二月' : 2,
            '三月' : 3,
            '四月' : 4,
            '五月' : 5,
            '六月' : 6,
            '七月' : 7,
            '八月' : 8,
            '九月' : 9,
            '十月' : 10,
            '十一月' : 11,
            '十二月' : 12,
        }
        let roll_all_chart;
        $(function () {
            showSales();
            showWindow();
            showQm();
            showSingle();
            showStockRoll();
            showAllSales(1);
            showAllSales(2);
            showAllSales(3);
            showTransfer(1);
            showTransfer(2);
            showTransfer(3);
            showReturn(2);
            showReturn(3);
            $("#return_win_show").on("click", function () {
                $(this).hide();
                $("#win_more").show();
                showSingle();
            });
            $("#return_qm_show").on("click", function () {
                $(this).hide();
                $("#qm_more").show();
                showQm();
            });
            $("#year").on('change', function () {
                showSales();
                showWindow();
                showQm();
                showSingle();
                $(".year").text($(this).val());
            });
            $("#month").on("change", function () {
                if ($(this).val() == '') {
                    $(".month").text("");
                }
                showSales();
                showWindow();
                $(".month").text($(this).val() + '月');
                $("#win_month").val($(this).val());
                $("#qm_month").val($(this).val());
                showQm();
                showSingle();
            });
            $("#distributions").select2();
            $("#dealers").select2();

            $("#qm_more").on("click", function() {
                showSingleDetail(1);
            });
            $("#win_more").on("click", function() {
                showSingleDetail(2);
            });

            $("#distributions").on("change", function () {
                if ($("#distributions").val() == '' || typeof $("#distributions").val() == 'undefined' || $("#distributions").val() == null) {
                    return;
                }
                showSales();
                showWindow();
                showQm();
                showSingle();
                $("#all_country").removeClass('btn-secondary').addClass('btn-primary');
                request.post('/admin/ajax/getDealers', {
                    creator_id: $("#distributions").val(),
                    t: 1,
                }).then(function (d) {
                    console.log(d);
                    let data = d.data;
                    $("#dealers").empty().append('<option selected disabled value="">选择经销商</option>');
                    if (data != '' && data.length > 0) {
                        for (let i in data) {
                            $("#dealers").append('<option value="' + data[i]['value'] + '">'+ data[i]['label'] +'</option>');
                        }
                    }
                });
            });

            $("#dealers").on('change', function () {
                $("#all_country").removeClass('btn-secondary').addClass('btn-primary');
                showSales();
                showWindow();
                showQm();
                showSingle();
            });

            $("#all_country").on('click', function () {
                $("#distributions").val('').trigger('change');
                $("#dealers").val('').empty().append('<option selected disabled value="">选择经销商</option>');
                $(this).removeClass('btn-primary').addClass('btn-secondary');
            });

            $("#export_all").on("click", function () {
            });
        });

        function showAllSales(type) {
            $.ajax({
                url: '/admin/stat/rollSale',
                type: 'get',
                data: {
                    type: type,
                },
                dataType: 'json',
                success: function (data) {
                    let list = data.list;
                    if (type == 1) {
                        $("#roll_qm_1").text(list.sale_qm_total);
                        $("#roll_win_1").text(list.sale_win_total);
                        $("#roll_qm_rate_1").text(list.sale_qm_rate + '%');
                        $("#roll_win_rate_1").text(list.sale_win_rate + '%');
                        $("#roll_qm_rate_2").text(list.sale_hb_qm_rate + '%');
                        $("#roll_win_rate_2").text(list.sale_hb_qm_rate + '%');
                    }
                    if (type == 2) {
                        $("#roll_qm_4").text(list.sale_qm_total);
                        $("#roll_win_4").text(list.sale_win_total);
                        $("#roll_qm_rate_5").text(list.sale_qm_rate + '%');
                        $("#roll_win_rate_5").text(list.sale_win_rate + '%');
                        $("#roll_qm_rate_6").text(list.sale_hb_qm_rate + '%');
                        $("#roll_win_rate_6").text(list.sale_hb_qm_rate + '%');
                    }
                    if (type == 3) {
                        $("#roll_qm_8").text(list.sale_qm_total);
                        $("#roll_win_8").text(list.sale_win_total);
                        $("#roll_qm_rate_11").text(list.sale_qm_rate + '%');
                        $("#roll_win_rate_11").text(list.sale_win_rate + '%');
                        $("#roll_qm_rate_12").text(list.sale_hb_qm_rate + '%');
                        $("#roll_win_rate_12").text(list.sale_hb_qm_rate + '%');
                    }
                }
            });
        }

        function showTransfer(type) {
            $.ajax({
                url: '/admin/stat/rollTransfer',
                type: 'get',
                data: {
                    type: type,
                },
                dataType: 'json',
                success: function (data) {
                    let list = data.list;
                    if (type == 1) {
                        $("#roll_qm_3").text(list.sale_qm_total);
                        $("#roll_win_3").text(list.sale_win_total);
                        $("#roll_qm_rate_3").text(list.sale_qm_rate + '%');
                        $("#roll_win_rate_3").text(list.sale_win_rate + '%');
                        $("#roll_qm_rate_4").text(list.sale_hb_qm_rate + '%');
                        $("#roll_win_rate_4").text(list.sale_hb_qm_rate + '%');
                    }
                    if (type == 2) {
                        $("#roll_qm_6").text(list.sale_qm_total);
                        $("#roll_win_6").text(list.sale_win_total);
                        $("#roll_qm_rate_7").text(list.sale_qm_rate + '%');
                        $("#roll_win_rate_7").text(list.sale_win_rate + '%');
                        $("#roll_qm_rate_8").text(list.sale_hb_qm_rate + '%');
                        $("#roll_win_rate_8").text(list.sale_hb_qm_rate + '%');
                    }
                    if (type == 3) {
                        $("#roll_qm_10").text(list.sale_qm_total);
                        $("#roll_win_10").text(list.sale_win_total);
                        $("#roll_qm_rate_13").text(list.sale_qm_rate + '%');
                        $("#roll_win_rate_13").text(list.sale_win_rate + '%');
                        $("#roll_qm_rate_14").text(list.sale_hb_qm_rate + '%');
                        $("#roll_win_rate_14").text(list.sale_hb_qm_rate + '%');
                    }
                }
            });
        }

        function showReturn(type) {
            $.ajax({
                url: '/admin/stat/rollReturn',
                type: 'get',
                data: {
                    type: type,
                },
                dataType: 'json',
                success: function (data) {
                    let list = data.list;
                    if (type == 2) {
                        $("#roll_qm_7").text(list.sale_qm_total);
                        $("#roll_win_7").text(list.sale_win_total);
                        $("#roll_qm_rate_9").text(list.sale_qm_rate + '%');
                        $("#roll_win_rate_9").text(list.sale_win_rate + '%');
                        $("#roll_qm_rate_10").text(list.sale_hb_qm_rate + '%');
                        $("#roll_win_rate_10").text(list.sale_hb_qm_rate + '%');
                    }
                    if (type == 3) {
                        $("#roll_qm_11").text(list.sale_qm_total);
                        $("#roll_win_11").text(list.sale_win_total);
                        $("#roll_qm_rate_15").text(list.sale_qm_rate + '%');
                        $("#roll_win_rate_15").text(list.sale_win_rate + '%');
                        $("#roll_qm_rate_16").text(list.sale_hb_qm_rate + '%');
                        $("#roll_win_rate_16").text(list.sale_hb_qm_rate + '%');
                    }
                }
            });
        }

        function showStockRoll() {
            $.ajax({
                url: '/admin/stat/rollStockAll',
                type: 'get',
                data: {},
                dataType: 'json',
                success: function (data) {
                    $("#roll_qm_2").text(data.list.stock_all_1);
                    $("#roll_win_2").text(data.list.stock_all_2);
                    $("#roll_qm_5").text(data.list.stock_dist_1);
                    $("#roll_win_5").text(data.list.stock_dist_2);
                    $("#roll_qm_9").text(data.list.stock_dealer_1);
                    $("#roll_win_9").text(data.list.stock_dealer_2);
                }
            });
        }

        function showSales() {
            $.ajax({
                url: '/admin/stat/roll_qm',
                type: 'get',
                data: {
                    year: $("#year").val(),
                    month: $("#month").val(),
                    dist_id: $("#distributions").val(),
                    dealer_id: $("#dealers").val(),
                },
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    console.log(data.months);
                    if (typeof data.list == 'undefined' || data.list.length <= 0) {
                        data.list = [];
                    }
                    roll_all_chart = Highcharts.chart('roll_sale',{
                        chart: {
                            type: 'column'
                        },
                        exporting: {
                            enabled: false,   // 关闭导出按钮
                        },
                        title: {
                            text: ''
                        },
                        subtitle: {
                            text: ''
                        },
                        xAxis: {
                            categories: data.months,
                            crosshair: true
                        },
                        credits: {
                            enabled: false
                        },
                        yAxis: {
                            min: 0,
                            title: '',
                        },
                        tooltip: {
                            // head + 每个 point + footer 拼接成完整的 table
                            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                                '<td style="padding:0"><b>{point.y} </b></td></tr>',
                            footerFormat: '</table>',
                            shared: true,
                            useHTML: true
                        },
                        plotOptions: {
                            column: {
                                dataLabels: {
                                    enabled: true,
                                },
                                cursor: 'pointer',
                                events: {
                                    click: function(event) {
                                        showQm(months[event.point.category])
                                    }
                                }
                            }
                        },
                        series: data.list
                    });
                }
            });
        }

        function showQm(month = '') {
            if (month != '') {
                $(".qm_month").text(month < 10 ? '0' + month + '月' : month + '月');
                $("#qm_month").val(month);
            }
            $.ajax({
                url: '/admin/stat/roll_single',
                type: 'get',
                data: {
                    year: $("#year").val(),
                    month: month != '' ? month : $("#qm_month").val(),
                    dist_id: $("#distributions").val(),
                    dealer_id: $("#dealers").val(),
                    type: 1,
                },
                dataType: 'json',
                success: function (data) {
                    if (typeof data.list == 'undefined' || data.list.length <= 0) {
                        data.list = [];
                    }
                    if (typeof data.roll_names == 'undefined' || data.roll_names.length <= 0) {
                        data.roll_names = [];
                    }
                    Highcharts.chart('roll_1', {
                        chart: {
                            type: 'bar'
                        },
                        title: {
                            text: ''
                        },
                        credits: {
                            enabled: false
                        },
                        subtitle: {
                            text: '    '
                        },
                        xAxis: {
                            categories: data.roll_names,
                            title: {
                                text: null
                            }
                        },
                        yAxis: {
                            min: 0,
                            title: {
                                text: '单品销量 (卷)',
                                align: 'high'
                            },
                            labels: {
                                overflow: 'justify'
                            }
                        },
                        tooltip: {
                            pointFormat: '<b>{point.y}</b>',
                        },
                        plotOptions: {
                            bar: {
                                dataLabels: {
                                    enabled: true,
                                },
                                cursor: 'pointer',
                                events: {
                                    click: function(event) {
                                        console.log(event);
                                    }
                                }
                            }
                        },
                        legend: {
                            layout: 'vertical',
                            align: 'right',
                            verticalAlign: 'top',
                            x: -40,
                            y: 100,
                            floating: true,
                            borderWidth: 1,
                            backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
                            shadow: true
                        },
                        series: data.list
                    });
                }
            });
        }

        function showWindow() {
            $.ajax({
                url: '/admin/stat/roll_window',
                type: 'get',
                data: {
                    year: $("#year").val(),
                    month: $("#month").val(),
                    dist_id: $("#distributions").val(),
                    dealer_id: $("#dealers").val(),
                },
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    if (typeof data.list == 'undefined' || data.list.length <= 0) {
                        data.list = [];
                    }
                    Highcharts.chart('roll_2',{
                        chart: {
                            type: 'column'
                        },
                        title: {
                            text: ''
                        },
                        subtitle: {
                            text: '     '
                        },
                        credits: {
                            enabled: false
                        },
                        xAxis: {
                            categories: data.months,
                            crosshair: true
                        },
                        yAxis: {
                            min: 0,
                            title: '',
                        },
                        tooltip: {
                            // head + 每个 point + footer 拼接成完整的 table
                            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                                '<td style="padding:0"><b>{point.y} </b></td></tr>',
                            footerFormat: '</table>',
                            shared: true,
                            useHTML: true
                        },
                        plotOptions: {
                            column: {
                                dataLabels: {
                                    enabled: true,
                                },
                                cursor: 'pointer',
                                events: {
                                    click: function(event) {
                                        console.log(event.point.category);
                                        showSingle(months[event.point.category])
                                    }
                                }
                            }
                        },
                        series: data.list
                    });
                }
            });
        }

        function showSingleDetail(type) {
            $.ajax({
                url: '/admin/stat/roll_single_detail',
                type: 'get',
                data: {
                    year: $("#year").val(),
                    month: type == 1 ? $("#qm_month").val() : $("#win_month").val(),
                    dist_id: $("#distributions").val(),
                    dealer_id: $("#dealers").val(),
                    type: type,
                },
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    if (typeof data.list == 'undefined' || data.list.length <= 0) {
                        data.list = [];
                    }
                    if (typeof data.roll_names == 'undefined' || data.roll_names.length <= 0) {
                        data.roll_names = [];
                    }
                    if (data.list == '' || typeof data.list == 'undefined') {
                        return;
                    }
                    let table = '<table class="table">';
                    table += '<thead><tr style="background-color: rgb(248, 248, 248);"><th>膜名称</th><th>卷数</th></tr></thead>';
                    for (let i in data.list) {
                        table += '<tr><td>' + data.list[i]['name'] + '</td><td>' + parseInt(data.list[i]['total']) + '</td></tr>';
                    }
                    table += '</table>';
                    if (type == 1) {
                        $("#return_qm_show").show();
                        $("#qm_more").hide();
                        $("#roll_1").empty().addClass('show-over').append(table);
                    }
                    if (type == 2) {
                        $("#win_more").hide();
                        $("#return_win_show").show();
                        $("#single_roll").empty().addClass('show-over').append(table);
                    }
                }
            });
        }

        function showSingle(month = '') {
            if (month != '') {
                $(".win_month").text(month < 10 ? '0' + month + '月' : month + '月');
                $("#win_month").val(month);
            }
            $.ajax({
                url: '/admin/stat/roll_single',
                type: 'get',
                data: {
                    year: $("#year").val(),
                    month: $("#win_month").val(),
                    dist_id: $("#distributions").val(),
                    dealer_id: $("#dealers").val(),
                    type: 2,
                },
                dataType: 'json',
                success: function (data) {
                    console.log(data);
                    if (typeof data.list == 'undefined' || data.list.length <= 0) {
                        data.list = [];
                    }
                    if (typeof data.roll_names == 'undefined' || data.roll_names.length <= 0) {
                        data.roll_names = [];
                    }
                    Highcharts.chart('single_roll', {
                        chart: {
                            type: 'bar'
                        },
                        title: {
                            text: ''
                        },
                        credits: {
                            enabled: false
                        },
                        subtitle: {
                            text: '    '
                        },
                        xAxis: {
                            categories: data.roll_names,
                            title: {
                                text: null
                            }
                        },
                        yAxis: {
                            min: 0,
                            title: {
                                text: '单品销量 (卷)',
                                align: 'high'
                            },
                            labels: {
                                overflow: 'justify'
                            }
                        },
                        tooltip: {
                            pointFormat: '<b>{point.y}</b>',
                        },
                        plotOptions: {
                            bar: {
                                dataLabels: {
                                    enabled: true,
                                    allowOverlap: true // 允许数据标签重叠
                                }
                            }
                        },
                        legend: {
                            layout: 'vertical',
                            align: 'right',
                            verticalAlign: 'top',
                            x: -40,
                            y: 100,
                            floating: true,
                            borderWidth: 1,
                            backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
                            shadow: true
                        },
                        series: data.list
                    });
                }
            });
        }
    </script>
@endsection
